package com.hmall.controller;

import com.hdmall.business.common.annotation.LoginRequired;
import com.hdmall.business.common.common.ServerResponse;
import com.hmall.model.SysUser;
import com.hmall.service.BiService;
import com.hmall.service.DealerService;
import com.hmall.util.TokenUtil;
import com.hmall.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * @ClassName BIController
 * @Description
 * @Author zhoutao
 * @Date 2018/12/18 9:13
 * @Version 2.0
 **/
@Api(value = "BI数据分析", description = "BI数据提供接口")
@RestController
@RequestMapping("/bi/")
public class BiController {


    private final
    BiService biService;

    private final
    DealerService dealerService;
    final
    JedisPool jedisPool;

    TokenUtil tokenUtil = new TokenUtil();

    @Autowired
    public BiController(BiService biService, JedisPool jedisPool, DealerService dealerService) {
        this.biService = biService;
        this.jedisPool = jedisPool;
        this.dealerService = dealerService;
    }

    /**
     * @Date 2018/12/18 9:18
     * @Param [token]
     * @return com.hmall.common.ServerResponse
     * @Description  //获得办事处和自己的用户名称列表
     */
    @LoginRequired
    @GetMapping("getBiBackFilterList")
    @ApiOperation(value = "根据业务员得到筛选信息", notes = "包括办事处名称和业务员名称")
    public ServerResponse getFilterList(String token) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return biService.getFilterList(user);
    }


    //根据月份得到几张表的数据
    //1.客户四维
    //2.成交用户统计
    //3.成交产品统计
    //4.成交量统计
    //5.成交金额统计
    //6.成交客单统计
    @LoginRequired
    @GetMapping("getBiBackData")
    @ApiOperation(value = "根据条件得到办事处以及业务员的相关数据信息",notes = "type 1业务员类型 2代表办事处类型 代表包括客户四维，成交用户，成交成品，成交金额，成交客单")
    public ServerResponse<BiDataVo> getBiData(String token, Integer type, Integer id, Integer year, Integer month){

        return biService.getBiData(type, id, year, month);

    }
    @LoginRequired
    @GetMapping("getBiBackProductDetail")
    @ApiOperation(value = "得到产品详情购买情况")
    public ServerResponse<List<SpecialNameAndWeightVo>> getProductDetail(String token, Integer type, Integer id, Integer year, Integer month, String productType){

        return biService.getProductDetail(type, id, year, month, productType);
    }
    @LoginRequired
    @GetMapping("getBiCustomerData")
    @ApiOperation(value = "得到公司的相关数据信息")
    public ServerResponse<BiTradeCustomerVo> getBiCustomer(String token, Integer customerId, Integer year, Integer month){

        return biService.getBiCustomerData(customerId, year, month);
    }
    @LoginRequired
    @GetMapping("getBiCustomerFilterList")
    @ApiOperation(value = "得到公司列表")
    public ServerResponse<PageVo<CustomerVo>> getBiCustomerFilterList(String token, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return dealerService.listCustomer(user.getUserId(), pageNum, pageSize);
    }






}
